<template>
  <div id='addshoptype'>
    <div class='addinfo'>
      <div
        class='addinfo-top'>
        <h4>{{cominfo}}</h4>
        <span
          class='el-icon-close'
          @click='send'></span>
      </div>
      <div
        class='addinfo-bottom'>
        <div class='infobox'>
          <span>*父级分类ID：</span>
          <input type="text"
            v-model='parentid'
            disabled=true>
        </div>
        <div class='infobox'>
          <span>*名称：</span>
          <input type="text"
            v-model='categoryname'>
        </div>
        <button
          @click='add'>提交</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'addshoptype',
  data() {
    return {
      categoryname: '',
    }
  },
  props: ['cominfo', 'parentid'],
  methods: {
    send() {
      this.flag = false
      this.$emit('func', this.flag)
    },
    add() {
      if (this.categoryname) {
        this.$axios({
          method: 'post',
          url: '/manage/category/add',
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
          params: {
            parentId: this.parentid,
            categoryName: this.categoryname,
          },
        }).then((res) => {
          if (res.status == 200) {
            this.$message.success('添加分类成功')
            this.$emit('func', this.flag)
            this.$emit('get')
            this.categoryname = ''
          }
        })
      } else {
        this.$message.error('请输入完整信息')
      }
    },
  },
}
</script>

<style lang='less'>
#addshoptype {
  background-color: rgba(0, 0, 0, 0.7);
  width: 100%;
  height: 100%;
  display: block;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;

  .addinfo {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: 460px;
    height: 260px;
    border-radius: 4px;
    background-color: #fff;
    margin: auto;
    .addinfo-top {
      width: 100%;
      height: 40px;
      border-bottom: 1px solid rgba(0, 0, 0, 0.178);
      position: absolute;
      margin-bottom: 30px;

      h4 {
        color: rgb(100, 100, 100);
        position: absolute;
        top: 50%;
        left: 30px;
        height: 30px;
        margin: -15px;
        text-align: center;
        line-height: 30px;
      }
      .el-icon-close {
        position: absolute;
        right: 10px;
        top: 10px;
        font-size: 18px;
        cursor: pointer;
        color: rgb(144, 147, 153);
      }
    }
    .addinfo-bottom {
      width: 100%;
      height: 180px;
      position: absolute;
      left: 0;
      bottom: 0;
      padding: 0px 15px 10px 15px;
      box-sizing: border-box;
      text-align: center;
      .infobox {
        width: 330px;
        text-align: right;
        margin-bottom: 20px;
        span {
          color: #646464;
          font-size: 16px;
          font-weight: 600;
        }
        input {
          outline: none;
          width: 160px;
          height: 25px;
          border: 1px solid #cbcbcb;
        }
      }
      button {
        width: 120px;
        height: 30px;
        outline: none;
        border: none;
        border-radius: 4px;
        background: rgb(64, 158, 255);
        cursor: pointer;
        color: #fff;
      }
    }
  }
}
</style>